﻿package mortal.game.view.ThanksGiving
{
    import Message.Public.*;
    import mortal.common.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.ThanksGiving.command.*;
    import mortal.game.view.ThanksGiving.data.*;
    import mortal.game.view.ThanksGiving.item.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class ThanksGivingController extends Controller
    {

        public function ThanksGivingController()
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            EventUtil.addSelfEvent(ThanksGivingEvent.ThanksGiOpenM, this.onOpenModuel, true);
            EventUtil.addNetEvent(ServerCommand.ThanksGivingConsumInfo, this.onConsumInfoBack, true);
            EventUtil.addSelfEvent(ThanksGivingEvent.ThanksGiGetConsumRw, this.onGetRechargeRw, true);
            LevelCheckUtil.addInit(this.initHd);
            EventUtil.addNetEvent(ServerCommand.NewDayUpdate, this.updateZero, true);
            Dispatcher.addEventListener(EventName.ActiveStart, this.onActionStar);
            Dispatcher.addEventListener(EventName.ActiveEnd, this.onActionEnd);
            return;
        }// end function

        private function onActionStar(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SClientActive;
            if (_loc_2.type == EActiveType._EActiveTypeThanksGiving)
            {
                ThanksGivingUtil2.activeShow = true;
                ThanksGivingIcon.instance.show();
                this.checkHasReward();
            }
            return;
        }// end function

        private function onActionEnd(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SClientActive;
            if (_loc_2.type == EActiveType._EActiveTypeThanksGiving)
            {
                ThanksGivingUtil2.activeShow = false;
                if (ThanksGivingIcon.hasInstance() && ThanksGivingIcon.instance.isHide == false)
                {
                    ThanksGivingIcon.instance.hide();
                }
                if (_view && _view.isHide == false)
                {
                    this.view.hide();
                }
            }
            return;
        }// end function

        override public function get view() : IView
        {
            if (_view == null)
            {
                _view = new ThanksGivingModule();
            }
            return _view;
        }// end function

        private function initHd(param1:Object) : void
        {
            return;
        }// end function

        private function updateZero(param1:Object) : void
        {
            var _loc_2:* = ClockManager.instance.getDelayDate(1000);
            ClockManager.instance.addDateCall(_loc_2, this.refleshDate);
            return;
        }// end function

        private function refleshDate() : void
        {
            this.initHd(null);
            this.onConsumInfoBack(null);
            return;
        }// end function

        private function onOpenModuel(event:DataEvent) : void
        {
            this.view.show();
            return;
        }// end function

        private function onConsumInfoBack(param1:Object) : void
        {
            if (_view && _view.isHide == false)
            {
                (_view as ThanksGivingModule).updateConsum();
            }
            this.checkHasReward();
            return;
        }// end function

        private function onGetRechargeRw(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            GameProxy.role.getThanksGivingConsumReward(_loc_2);
            this.checkHasReward();
            return;
        }// end function

        private function checkHasReward() : void
        {
            var _loc_1:* = ThanksGivingUtil.getRwIndex();
            if (_loc_1 != -1)
            {
                ThanksGivingIcon.instance.show();
                ThanksGivingIcon.instance.playEffect();
            }
            else if (ThanksGivingIcon.hasInstance() && ThanksGivingIcon.instance.isHide == false)
            {
                ThanksGivingIcon.instance.stopEffect();
            }
            return;
        }// end function

    }
}
